﻿@page "/UserLogin"
@using Carlife.Inf;
@using CarlifeService;
@using Commonality.DTO.AuthorityDTO;
@using ICarlifeService;
@using Microsoft.EntityFrameworkCore;
@using Models.Authority;
@using ICarlifeRespository;
@using CarlifeRespository;
@inject ILoginService login;
@inject IDbContextFactory<CarlifeDbcontext> dbFactory;
@inject NavigationManager NavigationManager;
@inject IJSRuntime jsRuntime
<PageTitle>登录</PageTitle>
<h3>登录</h3>
<div>
<p>
    登录帐号 ：
    <input @bind="username" type="text"></input>
</p>
<p>
    密码：
    <input @bind="password" type="password"></input>
</p>
<tr>
    <td>
        <div>@Message</div>
    </td>
</tr>
<input type="submit" class="btn btn-primary" @onclick="LoginSave" />
</div>
@code {
    private string Message = string.Empty;
    private static CarlifeDbcontext _context;
    private Users users = new Users();
    protected override Task OnInitializedAsync()
    {
        _context = dbFactory.CreateDbContext();
        return base.OnInitializedAsync();
    }
    private string username { get; set; }
    private string password { get; set; }
    private void LoginSave()
    {
        int count = login.GetGetLogin(username, password);
        if (count > 0)
        {
            jsRuntime.InvokeAsync<string>("alert", "登录成功 !");
            //Message = "登录成功 !";
            NavigationManager.NavigateTo($"UserIndex");
        }
        else
        {
            jsRuntime.InvokeAsync<string>("alert", "登录失败 !");
            //Message = "登录失败 !";
            return;
        }
        
    }
}
